package entry59;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.junit.Test;

class StackEmptyException extends Exception {
	private static final long serialVersionUID = 6725532833360115886L;
}

public class CheckException {
	class Stack<E> {
		private List<E> list = new ArrayList<E>();

		public void push(E e) {
			list.add(e);
		}

		public E pop() throws StackEmptyException {
			if (list.size() <= 0) {
				throw new StackEmptyException();
			}

			return list.remove(list.size() - 1);
		}

		public boolean isEmpty() {
			return list.isEmpty();
		}
	}

	@Test
	public void testCheckException() {
		Stack<String> stack = new Stack<String>();
		stack.push("test");

		try {
			String s = stack.pop();
			assertThat(s, is("test"));
		} catch (StackEmptyException e) {
			e.printStackTrace();
		}
	}
}
